package com.zw.shardedJedis.controller;

import com.zw.shardedJedis.config.ShardedJedisSentinelPool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import redis.clients.jedis.ShardedJedis;

/**
 * Created by zwz
 * date 2017/4/21
 * project com.zw.shardedJedis.controller
 */
@Controller
public class Demo {

    @Autowired
    ShardedJedisSentinelPool jedisSentinelPool;


    @RequestMapping("/testInsert")
    @ResponseBody
    public String testInsert() {
        try (ShardedJedis jedis = jedisSentinelPool.getResource()) {
            for (int i = 0; i < 30; i++) {
                jedis.set("test" + i, "test" + i + i);
            }
        }
        return "success";
    }
    @RequestMapping("/testQuery")
    @ResponseBody
    public String testQuery() {
        try (ShardedJedis jedis = jedisSentinelPool.getResource()) {
            return jedis.get("test19")+jedis.get("test1")+jedis.get("test0");
        }
    }
}
